package com.goodving.guli.bt;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.DialogFragment;
import android.app.DownloadManager;
import android.app.KeyguardManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.Time;
import android.view.Display;
import android.view.View;
import android.widget.ImageView;

import com.goodving.guli.R;
import com.goodving.guli.bt.dataprocess.DaySportData;
import com.goodving.guli.bt.dataprocess.SportData;
import com.goodving.guli.bt.dataprocess.SportDay;
import com.goodving.guli.bt.dataprocess.StepsInfo;
import com.goodving.guli.bt.eventbus.EventApkupgrade;
import com.goodving.guli.bt.lua.C1226h;
import com.goodving.guli.bt.model.DataManager;
import com.goodving.guli.bt.model.Friend;
import com.goodving.guli.bt.model.LoginData;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.model.ShareData;
import com.goodving.guli.bt.model.UserInfo;
import com.goodving.guli.bt.model.WeightGoal;
import com.goodving.guli.bt.model.WeightInfo;
import com.goodving.guli.bt.model.WeightInfoManager;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.HeartRateInfo;
import com.goodving.guli.bt.profile.scale.XMBLEManager;
import com.goodving.guli.bt.ui.C1894O;
import com.goodving.guli.bt.utils.C0893f;
import com.goodving.guli.bt.utils.ab;
import com.goodving.guli.bt.weight.BabyWeightUtil;
import com.goodving.guli.bt.weight.LuaUtil;
import com.goodving.guli.model.BraceletBtInfo;
import com.goodving.guli.model.DeviceSource;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.server.C0899d;
import com.goodving.guli.server.ClientDataConstants;
import com.goodving.guli.server.ClientConstant;
import com.goodving.guli.server.WebAPI;
import com.goodving.guli.server.WebRes;
import com.goodving.guli.server.WebResponse;
import com.goodving.guli.server.sync.SyncServerData;
import com.goodving.guli.utility.C1481u;
import com.goodving.guli.utility.Constants;
import com.goodving.guli.utility.gulihardware.Constant;
import com.goodving.guli.view.C3247b;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.AsyncHttpResponseHandler;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.UUID;

import cn.com.smartdevices.bracelet.chart.util.ChartData;
import cn.com.smartdevices.bracelet.config.C0886a;
import cn.com.smartdevices.bracelet.config.Config;
import cz.msebera.android.httpclient.Header;
import de.greenrobot.event.EventBus;

/**
 * Created by john on 2015/11/26.
 */
public class Utils {
    public static final String f3493a = "REF_DEVICE_TYPE";
    public static final String f3494b = "TYPE_BAND";
    public static final String f3495c = "TYPE_WEIGHT";
    public static final String f3496d = "TYPE_WEIGHT_PAIR";
    public static final String f3497e = "TYPE_UNLOCK_SCREEN";
    public static final String f3498f = "0";
    public static final String f3499g = "CHANGE_LOG";
    public static final String f3500h = "VERSION_NAME";
    public static final String f3501i = "APK_PATH";
    public static final boolean f3502j = true;
    public static final boolean f3503k = true;
    private static final String f3504l = "Utils";
    private static Gson mGson = null; // C2576k
    private static final String[] f3506n;
    private static final String[] f3507o;
    private static final String f3508p = "Millelet";
    private static long f3509q;
    private static int[] f3510r;

    static {
        f3506n = new String[]{"MI 2", "MI 2S"};
        f3507o = new String[]{"jt>", "aku", "blv", "cmw", "dnx", "eoy", "fpz", "gq!", "hr(", "is)"};
        f3509q = System.currentTimeMillis();
        f3510r = new int[]{Color.parseColor("#1094bf"), Color.parseColor("#575fbe"), Color.parseColor("#bc58b1"), Color.parseColor("#ff5b45"), Color.parseColor("#e98d25"), Color.parseColor("#7ea800")};
    }

    private Utils() {
    }

    @SuppressLint({"NewApi"})
    private static boolean m7958A(Context context) {
        return ((KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE)).isKeyguardSecure();
    }

    private static boolean m7959B(Context context) {
        int i;
        boolean j = true;
        Settings.SettingNotFoundException e;
        try {
            i = Settings.Secure.getInt(context.getContentResolver(), "bluetooth_unlock_status");
            try {
                GuliLog.tracePrintInfo(f3504l, "isUseUnlock:" + i + ", unlockAddress:" + Settings.Secure.getString(context.getContentResolver(), "bluetooth_address_to_unlock"));
            } catch (Throwable e2) {
                if (e2 instanceof Settings.SettingNotFoundException) {
                    e = (Settings.SettingNotFoundException)e2;
                    e.printStackTrace();
                    return i == 1 ? false : f3503k;
                }
            }
        } catch (Settings.SettingNotFoundException e3) {
            e = e3;
            i = 0;
            e.printStackTrace();
            if (i == 1) {
            }
        }
        if (i == 1) {
        }
        return j;
    }

    public static double m7960a(float f) {
        return 3.28d * ((double) f);
    }

    public static int m7961a(float f, Context context) {
        return (int) (((double) (context.getResources().getDisplayMetrics().scaledDensity * f)) + 0.5d);
    }

    public static int m7962a(int i) {
        return (int) Math.round(0.394d * ((double) i));
    }

    public static int m7963a(Context context, float f) {
        return (int) (0.5f + (context.getResources().getDisplayMetrics().density * f));
    }

    public static int m7964a(BitmapFactory.Options options, int i, int i2) {
        int i3 = options.outHeight;
        int i4 = options.outWidth;
        if (i3 <= i2 && i4 <= i) {
            return 1;
        }
        int round = Math.round(((float) i3) / ((float) i2));
        i3 = Math.round(((float) i4) / ((float) i));
        return round > i3 ? round : i3;
    }

    public static int m7965a(DaySportData.Summary summary) {
        int b = m8027b(summary.getSleepStartTime());
        return b > 720 ? b - 1440 : b;
    }

    public static int m7966a(Calendar calendar) {
        return (calendar.get(Calendar.YEAR) * 365) + calendar.get(Calendar.DAY_OF_YEAR);
    }

    public static int m7967a(byte[] bArr) {
        return ((((bArr[1059] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[1058] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[1057] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[1056] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static Bitmap m7968a(String str, int i, int i2) {
        Bitmap bitmap = null;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = f3503k;
        BitmapFactory.decodeFile(str, options);
        options.inSampleSize = m7964a(options, i, i2);
        options.inJustDecodeBounds = false;
        try {
            bitmap = BitmapFactory.decodeFile(str, options);
        } catch (Exception e) {
        }
        GuliLog.tracePrintInfo("WPJ", "createImageSafely:" + bitmap.getWidth() + "," + bitmap.getHeight() + "==" + options.inSampleSize);
        return bitmap;
    }

    public static Bitmap m7969a(byte[] bArr, int i, int i2) {
        int i3 = 1;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = f3503k;
        BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
        int i4 = options.outHeight;
        int i5 = options.outWidth;
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        if (i4 > i2) {
            i3 = Math.round(((float) i4) / ((float) i2));
        }
        if (i5 / i3 > i) {
            i3 = Math.round(((float) i5) / ((float) i));
        }
        options.inSampleSize = i3;
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
    }

    public static Bundle m7970a(int i, SportDay sportDay) {
        return m7971a(i, sportDay, ShareData.TimeType.DAY.ordinal());
    }

    public static Bundle m7971a(int i, SportDay sportDay, int i2) {
        Bundle bundle = new Bundle();
        bundle.putInt(ClientDataConstants.ax, i2);
        bundle.putInt("data_type", 0);
        bundle.putInt(ClientDataConstants.aw, i);
        bundle.putString("date", sportDay.toString());
        return bundle;
    }

    public static ShareData m7972a(Context context, int i, int i2, int i3, int i4, SportDay sportDay, ShareData shareData) {
        int daySportGoalSteps = Keeper.readPersonInfo().getDaySportGoalSteps();
        String[] a = ChartData.m8736a(context, i2);
        String str = a[0] + a[1];
        if (i3 > 0) {
            a = ChartData.m8736a(context, i2 - i3);
            str = a[0] + a[1];
            String[] a2 = ChartData.m8736a(context, i3);
            str = context.getString(R.string.share_step_description_run, new Object[]{str, a2[0] + a2[1], Integer.valueOf(i4)});
        } else {
            str = context.getString(R.string.share_step_description, new Object[]{str, Integer.valueOf(i4)});
        }
        if (daySportGoalSteps > i) {
            shareData.setType(1);
            shareData.title = context.getString(R.string.share_step_goal_failed_title);
            str = str + context.getString(R.string.share_goal_tips_fail);
        } else {
            shareData.setType(0);
            shareData.title = context.getString(R.string.share_step_goal_succ_title);
            str = str + context.getString(R.string.share_goal_tips_succ);
        }
        shareData.content = C3657a.f18328f + i;
        shareData.description = str;
        shareData.contentUnit = context.getString(R.string.unit_step);
        shareData.mExtraData = m7970a(i, sportDay);
        return shareData;
    }

    public static UserInfo m7973a(PersonInfo personInfo) {
        int i = 10;
        byte[] bytes = personInfo.nickname.getBytes();
        if (bytes.length <= 10) {
            i = bytes.length;
        }
        byte[] obj = new byte[i];// TBD
        System.arraycopy(bytes, 0, obj, 0, i);
        return new UserInfo((int) personInfo.uid, (byte) personInfo.gender, (byte) personInfo.age, (byte) personInfo.height, (byte) ((int) personInfo.weight), obj);
    }

    public static String m7974a(Context context) {
        return m8079j(context) + "/MiBand_" + Calendar.getInstance().getTimeInMillis() + "_" + C4220a.cb;
    }

    public static String m7975a(Context context, double d) {
        GuliLog.tracePrintInfo(f3504l, "get ranking percent : " + d);
        Resources resources = context.getResources();
        if (d == 0.0d) {
            return Html.fromHtml(resources.getString(R.string.sport_ranking_desc_poor, new Object[]{C3657a.f18328f})).toString();
        } else if (d >= 99.99d) {
            return Html.fromHtml(resources.getString(R.string.sport_ranking_desc_great)).toString();
        } else {
            String str = C3657a.f18328f;
//            str = d <= 99.0d ? C1006h.m9715b(d, 1) : C1006h.m9715b(d, 2);
            return resources.getString(R.string.share_step_ranking, new Object[]{str + resources.getString(R.string.percent_mark)});
        }
    }

    public static String m7976a(Context context, int i) {
        if (!m8016a(Keeper.readSyncTime(DataManager.m12179a().m12239r()))) {
            return context.getString(R.string.dynamic_pull_not_sync_today);
        }
        return context.getString(i, new Object[]{C0893f.m9088a(new Date(Keeper.readSyncTime(DataManager.m12179a().m12239r())))});
    }

    public static String m7977a(Context context, int i, int i2) {
        if (!m8016a(Keeper.readSyncTime(i2))) {
            return context.getString(R.string.dynamic_pull_not_sync_today);
        }
        return context.getString(i, new Object[]{C0893f.m9088a(new Date(Keeper.readSyncTime(i2)))});
    }

    public static String m7978a(Context context, int i, int i2, int i3, String str, int i4, int i5) {
        String str2 = C3657a.f18328f;
        String[] a = ChartData.m8736a(context, i2);
        str2 = a[0] + a[1];
        String b = m8032b(i2);
        String e = m8062e(context, i2);
        if (i5 > 0) {
            a = ChartData.m8736a(context, i5);
            str2 = a[0] + a[1];
            String[] a2 = ChartData.m8736a(context, i2 - i5);
            return context.getString(R.string.share_step_description_monthly_run, new Object[]{a2[0] + a2[1], str2, e, b, str, i4 + C3657a.f18328f});
        }
        return context.getString(R.string.share_step_description_monthly, new Object[]{str2, e, Integer.valueOf(i3), b, str, i4 + C3657a.f18328f});
    }

    public static String m7979a(Context context, int i, int i2, String str, int i3, int i4) {
        String[] a = ChartData.m8736a(context, i);
        String str2 = a[0] + a[1];
        String e = m8062e(context, i);
        String str3 = C3657a.f18328f;
        if (i4 <= 0) {
            if (!TextUtils.isEmpty(e)) {
                e = ", " + e;
            }
            return context.getString(R.string.share_step_description_weekly, new Object[]{str2, e, Integer.valueOf(i2), str, i3 + C3657a.f18328f});
        }
        String[] a2 = ChartData.m8736a(context, i - i4);
        str2 = a2[0] + a2[1];
        String[] a3 = ChartData.m8736a(context, i4);
        str3 = a3[0] + a3[1];
        return context.getString(R.string.share_step_description_weekly_run, new Object[]{str2, str3, e, str, i3 + C3657a.f18328f});
    }
//
//    public static String m7980a(Context context, ReportData reportData) {
//        int steps = reportData.getSteps();
//        int distance = reportData.getDistance();
//        int continueDays = reportData.getContinueDays();
//        int runDistance = reportData.getRunDistance();
//        String e = m8062e(context, distance);
//        String str = (steps / continueDays) + C3657a.f18328f;
//        String[] stringArray = context.getResources().getStringArray(R.array.fortune);
//        String str2 = C3657a.f18328f;
//        int length = stringArray.length;
//        if (length >= 0) {
//            str2 = stringArray[Calendar.getInstance().get(6) % length];
//        }
//        stringArray = ChartData.m8736a(context, distance);
//        String str3 = stringArray[0] + stringArray[1];
//        if (runDistance <= 0) {
//            return context.getString(R.string.share_continue_goal_format, new Object[]{str3, str, e, str2});
//        }
//        String[] a = ChartData.m8736a(context, runDistance);
//        str = a[0] + a[1];
//        String[] a2 = ChartData.m8736a(context, distance - runDistance);
//        return context.getString(R.string.share_continue_goal_format_run, new Object[]{a2[0] + a2[1], str, e, str2});
//    }
//
//    public static String m7981a(Context context, AlarmClockItem alarmClockItem) {
//        StringBuilder stringBuilder = new StringBuilder();
//        int days = alarmClockItem.getDays();
//        if (days == AlarmClockItem.ALARM_ONCE) {
//            return context.getString(R.string.alarm_once);
//        }
//        if (days == AlarmClockItem.ALARM_EVERY_DAY) {
//            return context.getString(R.string.everyday);
//        }
//        if (days == AlarmClockItem.ALARM_MON_2_FRI) {
//            return context.getString(R.string.mon_fri);
//        }
//        if (days == AlarmClockItem.ALARM_MON_2_SAT) {
//            return context.getString(R.string.mon_sat);
//        }
//        int i = 0;
//        for (int i2 = days; i2 > 0; i2 >>= 1) {
//            if ((i2 & 1) == 1) {
//                i++;
//            }
//        }
//        String[] stringArray = context.getResources().getStringArray(R.array.weeks_short);
//        String[] stringArray2 = context.getResources().getStringArray(R.array.weeks);
//        if (i <= 1) {
//            stringArray = stringArray2;
//        }
//        int i3 = i;
//        for (int i4 = 0; i4 < 7; i4++) {
//            if (((1 << i4) & days) != 0) {
//                stringBuilder.append(stringArray[i4]);
//                i3--;
//                if (i3 > 0) {
//                    stringBuilder.append(" ");
//                }
//            }
//        }
//        if (stringBuilder.length() > 0 && i > 1) {
//            stringBuilder.insert(0, context.getResources().getString(R.string.week));
//        }
//        return stringBuilder.toString();
//    }

    public static String m7982a(Context context, String str) {
        String str2 = C3657a.f18328f;
        try {
            Class loadClass = context.getClassLoader().loadClass("android.os.SystemProperties");
            return (String) loadClass.getMethod("get", new Class[]{String.class}).invoke(loadClass, new Object[]{str});
        } catch (IllegalArgumentException e) {
            throw e;
        } catch (Exception e2) {
            return C3657a.f18328f;
        }
    }

//    public static String m7983a(Bitmap bitmap) {
//        return m7984a(bitmap, 100);
//    }

//    public static String m7984a(Bitmap bitmap, int i) {
//        String str = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp.jpg";
//        m8022a(str, bitmap, i);
//        return str;
//    }

//    public static String m7985a(View view, Context context) {
//        String a = m7974a(context);
//        view.buildDrawingCache();
//        return m8022a(a, view.getDrawingCache(), 85) ? a : C3657a.f18328f;
//    }

//    public static String m7986a(AlarmClockItem alarmClockItem) {
//        return m7987a(alarmClockItem, false);
//    }
//
//    public static String m7987a(AlarmClockItem alarmClockItem, boolean z) {
//        int i = 12;
//        int i2 = alarmClockItem.getCalendar().get(11);
//        int i3 = alarmClockItem.getCalendar().get(12);
//        if (z) {
//            i = i2;
//        } else {
//            i2 = alarmClockItem.getCalendar().get(10);
//            if (i2 != 0) {
//                i = i2;
//            }
//        }
//        return (i < 10 ? f3498f + i : Integer.valueOf(i)) + C4220a.ci + (i3 < 10 ? f3498f + i3 : Integer.valueOf(i3));
//    }

    public static String m7988a(String str, String str2, String str3) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(str2, Locale.getDefault());
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            Date parse = simpleDateFormat.parse(str);
            SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat(str3, Locale.getDefault());
            simpleDateFormat2.setTimeZone(TimeZone.getDefault());
            return simpleDateFormat2.format(Long.valueOf(parse.getTime()));
        } catch (Exception e) {
            return null;
        }
    }

    public static ArrayList<String> m7989a(SportDay sportDay) {
        ArrayList arrayList = null;
        ArrayList<String> d = m8060d();
        if (d == null) {
            arrayList = new ArrayList();
        } else {
            ArrayList<String> arrayList2 = d;
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            if (sportDay.toString().equals((String) it.next())) {
                break;
            }
        }
        arrayList.add(sportDay.toString());
//        m8054c(arrayList);
        return arrayList;
    }

    public static ArrayList<SportData> m7990a(ArrayList<SportData> arrayList) {
        ArrayList<SportData> arrayList2 = new ArrayList(arrayList.size());
        try {
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                arrayList2.add(((SportData) it.next()).copy());
            }
        } catch (Throwable e) {
            if (e instanceof CloneNotSupportedException) {
                e.printStackTrace();
                arrayList2.clear();
            }
        }
        return arrayList2;
    }

    public static void m7991a(Activity activity) {
        if (activity != null) {
            try {
                DialogFragment dialogFragment = (DialogFragment) activity.getFragmentManager().findFragmentByTag(ProgressDimFragment.class.getName());
                if (dialogFragment != null) {
                    dialogFragment.dismiss();
                }
            } catch (Exception e) {
            }
        }
    }

    public static void m7992a(Activity activity, int i) {
        m7993a(activity, i, (boolean) f3503k);
    }

    public static void m7993a(Activity activity, int i, boolean z) {
        if (activity != null) {
            m7991a(activity);
            try {
                Bundle bundle = new Bundle();
                bundle.putString(C4220a.bA, activity.getString(i));
                bundle.putBoolean(C4220a.bB, z);
                DimPanelFragment.showPanel(activity, ProgressDimFragment.class, bundle);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

//    public static void m7994a(Activity activity, boolean z) {
//        WebAPI.m11596a(C0886a.m9071f(activity), Config.m8865b(), new C0657T(z, activity));
//    }
//
//    public static void m7995a(Context context, Bundle bundle, C0899d c0899d) {
//        if (bundle == null) {
//            bundle = new Bundle();
//            bundle.putInt(ClientDataConstants.ax, TimeType.DAY.ordinal());
//            bundle.putString("date", new SportDay().toString());
//        }
//        if (bundle != null) {
//            int i = -1;
//            if (bundle.containsKey(ClientDataConstants.ax)) {
//                i = bundle.getInt(ClientDataConstants.ax);
//            }
//            if (i == TimeType.DAY.ordinal()) {
//                Object a = C0855b.m8954a(context.getApplicationContext()).m8958a(C0889b.f4471a, (boolean) f3503k);
//                if (!TextUtils.isEmpty(a)) {
//                    try {
//                        JSONObject jSONObject = new JSONObject(a);
//                        String string = jSONObject.getString("date");
//                        String string2 = bundle.getString("date");
//                        int i2 = jSONObject.getInt(ClientDataConstants.aw);
//                        int i3 = bundle.getInt(ClientDataConstants.aw);
//                        int i4 = jSONObject.getInt(ClientDataConstants.ax);
//                        if (string != null && string.equals(string2) && i2 / 100 == i3 / 100 && i4 == i) {
//                            c0899d.m9109a(Double.valueOf(jSONObject.getString(C0862i.f4387b)).doubleValue());
//                            return;
//                        }
//                    } catch (JSONException e) {
//                        GuliLog.m12370d(f3504l, "rank:" + e.getMessage());
//                    }
//                }
//                m8041b(context, bundle, c0899d);
//            }
//        }
//    }

//    public static void m7996a(Context context, C0899d c0899d) {
//        m7995a(context, null, c0899d);
//    }
//
//    public static void m7997a(Context context, Location location) {
//        GuliLog.tracePrintInfo(f3504l, "Location : " + location.m12115b() + "  " + location.m12112a());
//        Address c = location.m12117c();
//        if (c != null) {
//            GuliLog.tracePrintInfo(f3504l, "cityCode : " + c.m12109i() + ", countryCode: " + c.m12095b());
//            String i = c.m12109i();
//            Object obj = null;
//            if (!(TextUtils.isEmpty(i) || i.equals(Keeper.readCityCode()))) {
//                Keeper.keepCityCode(i);
//                obj = 1;
//            }
//            String b = c.m12095b();
//            if (!(TextUtils.isEmpty(b) || b.equals(Keeper.readCountryCode()))) {
//                Keeper.keepCountryCode(b);
//                obj = 1;
//            }
//            if (obj != null) {
//                m7998a(context, Keeper.readPersonInfo());
//            }
//        }
//    }

    static final class C0664Y extends AsyncHttpResponseHandler {
        final /* synthetic */ PersonInfo f3512a;
        final /* synthetic */ Context f3513b;

        C0664Y(PersonInfo personInfo, Context context) {
            this.f3512a = personInfo;
            this.f3513b = context;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.m12370d("Utils", "Sync person info to server fail : " + bArr + ", statusCode " + i + ", error");
            th.printStackTrace();
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            String b = Utils.m8035b(bArr);
            GuliLog.m12370d("Utils", "update person info onSuccess:" + i + ",content:" + b);
            String str = this.f3512a.avatarUrl;
            if (WebRes.m11644a(this.f3513b, b, this.f3512a).m11659c()) {
                GuliLog.tracePrintInfo("Utils", "update avatar onSuccess:" + i + ", avatarUrl=" + this.f3512a.avatarUrl);
                C1226h.m11372a().m11387d(str);
            }
            this.f3512a.clearNeedSyncServer();
            Keeper.keepPersonInfo(this.f3512a);
        }
    }

    public static void m7998a(Context context, PersonInfo personInfo) {
        if (personInfo.isValid()) {
            WebAPI.m11604a(C0886a.m9071f(context), personInfo, new C0664Y(personInfo, context));
        } else {
            GuliLog.tracePrintInfo(f3504l, "personInfo is inValid!");
        }
    }

    static final class C0665Z extends AsyncHttpResponseHandler {
        final /* synthetic */ af f3514a;
        final /* synthetic */ Context f3515b;
        final /* synthetic */ PersonInfo f3516c;

        C0665Z(af afVar, Context context, PersonInfo personInfo) {
            this.f3514a = afVar;
            this.f3515b = context;
            this.f3516c = personInfo;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.tracePrintInfo("WPJ", "onFailure:" + i + ",content:" + Utils.m8035b(bArr));
            C1894O.m15166a();
            if (this.f3514a != null) {
                this.f3514a.m8240a();
            }
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            String b = Utils.m8035b(bArr);
            GuliLog.tracePrintInfo("Utils", "update Profile onSuccess:" + i + ",content:" + b);
            WebResponse a = WebResponse.getWebResponse(this.f3515b, b);
            C1894O.m15166a();
            if (a.m11659c()) {
                Keeper.keepPersonInfo(this.f3516c);
                if (this.f3514a != null) {
                    this.f3514a.m8241b();
                }
            } else if (this.f3514a != null) {
                this.f3514a.m8240a();
            }
        }
    }

    public static void m7999a(Context context, PersonInfo personInfo, HashMap<String, String> hashMap, af afVar) {
        WebAPI.m11613a(C0886a.m9071f(context), (HashMap) hashMap, new C0665Z(afVar, context, personInfo));
    }

    static final class C0650O extends AsyncHttpResponseHandler {
        final /* synthetic */ ad f3473a;
        final /* synthetic */ WeightGoal f3474b;

        C0650O(ad adVar, WeightGoal weightGoal) {
            this.f3473a = adVar;
            this.f3474b = weightGoal;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.tracePrintInfo("Utils", "upload person target fail");
            this.f3473a.m8237a();
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            if (bArr != null) {
                GuliLog.tracePrintInfo("Utils", "Response syncTargetWeightToServer: " + new String(bArr));
                this.f3473a.m8238a(this.f3474b);
                return;
            }
            this.f3473a.m8237a();
        }
    }

    public static void m8000a(Context context, WeightGoal weightGoal, ad adVar) {
        GuliLog.tracePrintInfo(f3504l, "Keeper.readLoginData().uid " + C0886a.m9071f(context).uid);
        GuliLog.tracePrintInfo(f3504l, "weight " + weightGoal.currentVal);
        GuliLog.tracePrintInfo(f3504l, "fuid" + weightGoal.fuid);
        GuliLog.tracePrintInfo(f3504l, "targetWeigt " + weightGoal.goal);
        GuliLog.tracePrintInfo(f3504l, "height " + weightGoal.height);
        GuliLog.tracePrintInfo(f3504l, "timestamp " + weightGoal.datetime);
        WebAPI.uploadUserWeightGoal(context, C0886a.m9071f(context).uid + C3657a.f18328f, weightGoal.fuid + C3657a.f18328f, 1, weightGoal.currentVal, weightGoal.goal, weightGoal.height, weightGoal.datetime, new C0650O(adVar, weightGoal));
    }
//
//    public static void m8001a(Context context, DaySportData daySportData, ShareData shareData) {
//        if (daySportData != null && shareData != null) {
//            int u = ChartData.m8731a().m8817u();
//            String a;
//            String str;
//            String string;
//            String string2;
//            if (u == 1) {
//                StepsInfo stepsInfo = daySportData.getStepsInfo();
//                if (stepsInfo == null) {
//                    stepsInfo = new StepsInfo();
//                }
//                a = C0893f.m9086a(context, stepsInfo.getStepsTimeCount() + stepsInfo.getRunTimeCount());
//                str = C3657a.f18328f;
//                if (stepsInfo.getRunTimeCount() > 0) {
//                    str = ", " + context.getString(R.string.ran) + C0893f.m9086a(context, stepsInfo.getRunTimeCount());
//                }
//                string = context.getString(R.string.share_goal_tips_fail);
//                shareData.setType(1);
//                if (stepsInfo.getStepsCount() >= Keeper.readPersonInfo().getDaySportGoalSteps()) {
//                    string2 = context.getString(R.string.share_goal_tips_succ);
//                    shareData.setType(0);
//                } else {
//                    string2 = string;
//                }
//                shareData.description = context.getString(R.string.main_ui_share_tips, new Object[]{a, str, string2});
//            } else if (u == 16) {
//                SleepInfo sleepInfo = daySportData.getSleepInfo();
//                if (sleepInfo == null) {
//                    sleepInfo = new SleepInfo();
//                }
//                string = C0893f.m9085a(sleepInfo.getStartDateMin());
//                a = C0893f.m9085a(sleepInfo.getStopDateMin());
//                String a2 = C0893f.m9086a(context, sleepInfo.getRemCount());
//                GuliLog.tracePrintInfo(f3504l, "awake num = " + sleepInfo.getAwakeNum() + ", count = " + sleepInfo.getAwakeCount());
//                str = C3657a.f18328f;
//                int awakeNum = sleepInfo.getAwakeNum();
//                if (awakeNum == 1) {
//                    string2 = context.getString(R.string.awake_format_1);
//                } else if (awakeNum > 1) {
//                    string2 = context.getString(R.string.awake_format, new Object[]{Integer.valueOf(sleepInfo.getAwakeNum())});
//                } else {
//                    string2 = str;
//                }
//                shareData.description = context.getString(R.string.main_ui_sleep_share_tips, new Object[]{a2, string2, string, a});
//            }
//        }
//    }
//
//    public static void m8002a(Context context, StepsInfo stepsInfo, ShareData shareData) {
//        m7972a(context, stepsInfo.getStepsCount(), stepsInfo.getDistance(), stepsInfo.getRunDistance(), stepsInfo.getCalories(), stepsInfo.getSportDay(), shareData);
//    }

    static final class C0651P extends AsyncHttpResponseHandler {
        final /* synthetic */ ab f3475a;

        C0651P(ab abVar) {
            this.f3475a = abVar;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.tracePrintInfo("Utils", "delete user weight target fail");
            this.f3475a.m8147b();
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            if (bArr != null) {
                GuliLog.tracePrintInfo("Utils", "Response delete user target weight : " + new String(bArr));
                this.f3475a.m8146a();
                return;
            }
            this.f3475a.m8147b();
        }
    }

    public static void m8003a(Context context, String str, long j, ab abVar) {
        GuliLog.tracePrintInfo(f3504l, "Keeper.readLoginData().uid " + C0886a.m9071f(context).uid);
        GuliLog.tracePrintInfo(f3504l, "fuid" + str);
        GuliLog.tracePrintInfo(f3504l, "timestamp " + j);
        WebAPI.uploadUserWeightGoal(context, C0886a.m9071f(context).uid + C3657a.f18328f, str, 1, j, new C0651P(abVar));
    }

    static final class C0652Q extends AsyncHttpResponseHandler {
        final /* synthetic */ Context f3480a;
        final /* synthetic */ ac f3481b;

        C0652Q(Context context, ac acVar) {
            this.f3480a = context;
            this.f3481b = acVar;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.tracePrintInfo("Utils", "get from server fail");
            this.f3481b.m8148a(null);
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            if (bArr != null) {
                String str = new String(bArr);
                GuliLog.tracePrintInfo("Utils", "Response getTargetWeightGoalFromServer : " + str);
                if (WebResponse.getWebResponse(this.f3480a, str).m11659c()) {
                    List j = Utils.m8082k(str);
                    if (j == null || j.size() <= 0) {
                        GuliLog.tracePrintInfo("Utils", " info size is null or 0");
                        this.f3481b.m8148a(null);
                        return;
                    }
                    GuliLog.tracePrintInfo("Utils", "item size is " + j.size());
                    this.f3481b.m8148a((WeightGoal) j.get(0));
                    return;
                }
                this.f3481b.m8148a(null);
            }
        }
    }

    public static void m8004a(Context context, String str, long j, ac acVar) {
        WebAPI.getUserWeightGoalList(context, C0886a.m9071f(context).uid + C3657a.f18328f, str, 1, j + C3657a.f18328f, 1, new C0652Q(context, acVar));
    }

    static final class aa extends AsyncHttpResponseHandler {
        final /* synthetic */ Context f3584a;
        final /* synthetic */ ae f3585b;

        aa(Context context, ae aeVar) {
            this.f3584a = context;
            this.f3585b = aeVar;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.tracePrintInfo("Utils", "getUserTargetWeightListfail");
            this.f3585b.m8239a(null);
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            if (bArr != null) {
                String str = new String(bArr);
                GuliLog.tracePrintInfo("Utils", "Response getTargetWeightGoalFromServer : " + str);
                if (WebResponse.getWebResponse(this.f3584a, str).m11659c()) {
                    List j = Utils.m8082k(str);
                    if (j == null || j.size() <= 0) {
                        GuliLog.tracePrintInfo("Utils", " info size is null or 0");
                        this.f3585b.m8239a(null);
                        return;
                    }
                    GuliLog.tracePrintInfo("Utils", "item size is " + j.size());
                    this.f3585b.m8239a(j);
                    return;
                }
                this.f3585b.m8239a(null);
            }
        }
    }

    public static void m8005a(Context context, String str, String str2, String str3, ae aeVar) {
        GuliLog.tracePrintInfo(f3504l, "Keeper.readLoginData().uid " + C0886a.m9071f(context).uid);
        GuliLog.tracePrintInfo(f3504l, "fuid" + str);
        GuliLog.tracePrintInfo(f3504l, "stime " + str2);
        GuliLog.tracePrintInfo(f3504l, "etime " + str3);
        WebAPI.getUserWeightGoalList(context, C0886a.m9071f(context).uid + C3657a.f18328f, str, 1, str2, str3, new aa(context, aeVar));
    }

//    public static void m8006a(TextView textView, SpannableString spannableString) {
//        textView.setHighlightColor(0);
//        textView.append(" ");
//        textView.append(spannableString);
//        textView.setMovementMethod(LinkMovementMethod.getInstance());
//        textView.setOnLongClickListener(new C0649N());
//    }

    @SuppressLint({"NewApi"})
    public static void m8007a(PersonInfo personInfo, ImageView imageView) {
        Bitmap bitmap = null;
        if (!(personInfo.avatarPath == null || personInfo.avatarPath.equals(C3657a.f18328f))) {
            bitmap = C1226h.m11372a().m11375a(Uri.fromFile(new File(personInfo.avatarPath)).toString());
            GuliLog.tracePrintInfo(f3504l, "path=" + personInfo.avatarPath + " avatarBitmap=" + bitmap);
            if (bitmap != null) {
                imageView.setBackground(new BitmapDrawable(C1894O.m15165a(bitmap)));
            }
        }
        if (bitmap == null) {
            GuliLog.tracePrintInfo(f3504l, "avatar Url =" + personInfo.avatarUrl);
            C1226h.m11372a().m11383b(personInfo.avatarUrl, imageView);
            GuliLog.tracePrintInfo(f3504l, "after load avatar Url =" + personInfo.avatarUrl);
            return;
        }
        bitmap.recycle();
    }

    @SuppressLint({"NewApi"})
    public static void m8008a(com.goodving.guli.bt.weight.UserInfo userInfo, ImageView imageView) {
        if (userInfo != null) {
            if (userInfo.uid == -1) {
                Bitmap bitmap;
                PersonInfo readPersonInfoForScale = Keeper.readPersonInfoForScale();
                GuliLog.tracePrintInfo(f3504l, "read the person info avatarPath is " + readPersonInfoForScale.avatarPath);
                if (readPersonInfoForScale.avatarPath == null || readPersonInfoForScale.avatarPath.isEmpty()) {
                    bitmap = null;
                } else {
                    bitmap = C1226h.m11372a().m11375a(Uri.fromFile(new File(readPersonInfoForScale.avatarPath)).toString());
                }
                if (bitmap != null) {
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    try {
                        bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                        userInfo.avatarSource = byteArrayOutputStream.toByteArray();
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e) {
                            }
                        }
                    } catch (Exception e2) {
                        GuliLog.tracePrintError(f3504l, e2.getMessage());
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e3) {
                            }
                        }
                    } catch (Throwable th) {
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e4) {
                            }
                        }
                    }
                    bitmap.recycle();
                }
            }
            if (null == null && userInfo.avatarSource != null && userInfo.avatarSource.length > 0) {
                byte[] bArr = userInfo.avatarSource;
                Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length);
                GuliLog.tracePrintInfo(f3504l, "path=" + userInfo.avatarUrl + " avatarBitmap=" + decodeByteArray);
                if (decodeByteArray != null) {
                    imageView.setBackground(new BitmapDrawable(C1894O.m15165a(decodeByteArray)));
                    decodeByteArray.recycle();
                    GuliLog.tracePrintInfo(f3504l, "set background from avatarSource");
                    return;
                }
                imageView.setBackgroundResource(R.drawable.default_userinfo);
                return;
            } else if (!(userInfo.avatarUrl == null || userInfo.avatarUrl.equals(C3657a.f18328f))) {
                imageView.setBackgroundResource(R.drawable.default_userinfo);
                GuliLog.tracePrintInfo(f3504l, "avatar Url =" + userInfo.avatarUrl);
                C1226h.m11372a().m11383b(userInfo.avatarUrl, imageView);
                return;
            }
        }
        imageView.setBackgroundResource(R.drawable.default_userinfo);
    }

//    public static void m8010a(String str, int i, Activity activity) {
//        m8011a(str, i, (Context) activity, 2);
//    }

//    public static void m8011a(String str, int i, Context context, int i2) {
//        Intent intent = new Intent(context, WebActivity.class);
//        intent.putExtra(C4220a.f20881d, i2);
//        intent.putExtra(C4220a.f20882e, str);
//        intent.putExtra(Constant.aS, i);
//        context.startActivity(intent);
//    }
//
//    public static void m8012a(String str, String str2, byte[] bArr) {
//        int length = bArr.length;
//        GuliLog.tracePrintInfo(str, "=============================" + str2 + "============================i");
//        for (int i = 0; i < length; i += 3) {
//            C3903a c3903a = new C3903a(bArr[i + 1], bArr[i + 2], bArr[i]);
//            GuliLog.tracePrintInfo(str, new SportData(i / 3, c3903a.f19681e & HeartRateInfo.HR_EMPTY_VALUE, c3903a.f19679c & HeartRateInfo.HR_EMPTY_VALUE, c3903a.f19680d & HeartRateInfo.HR_EMPTY_VALUE).toString());
//        }
//        GuliLog.tracePrintInfo(str, "=============================" + str2 + "============================o");
//    }
//
    public static void m8013a(boolean z) {
        if (m8024a(Keeper.readLastCheckUpdateDate(), Calendar.getInstance()) || z) {
            Keeper.keepCheckUpdateApkDate();
            EventBus.getDefault().post(new EventApkupgrade(z));
            return;
        }
        GuliLog.m12370d(f3504l, "Today has checked upgrade.");
    }

    public static void m8014a(boolean z, String str) {
        if (z) {
            f3509q = System.currentTimeMillis();
        }
        long currentTimeMillis = System.currentTimeMillis();
        GuliLog.tracePrintInfo("Debug", str + ": " + (currentTimeMillis - f3509q));
        f3509q = currentTimeMillis;
    }

    public static boolean m8015a() {
        String str = Build.MODEL;
        GuliLog.tracePrintInfo(f3504l, "model:" + str);
        for (String equals : f3506n) {
            if (equals.equals(str)) {
                return f3503k;
            }
        }
        return false;
    }

    public static boolean m8016a(long j) {
        Time time = new Time();
        time.set(j);
        int i = time.year;
        int i2 = time.month;
        int i3 = time.monthDay;
        time.set(System.currentTimeMillis());
        return (i == time.year && i2 == time.month && i3 == time.monthDay) ? f3503k : false;
    }

    public static boolean m8017a(View view, int i, int i2) {
        int[] iArr = new int[2];
        view.getLocationOnScreen(iArr);
        int i3 = iArr[0];
        int i4 = iArr[1];
        return (i < i3 || i > i3 + view.getWidth() || i2 < i4 || i2 > i4 + view.getHeight()) ? false : f3503k;
    }

//    public static boolean m8018a(InputStream inputStream, File file) {
//        FileOutputStream fileOutputStream;
//        Exception e;
//        Throwable th;
//        try {
//            fileOutputStream = new FileOutputStream(file);
//            try {
//                byte[] bArr = new byte[C2122b.f11939a];
//                while (true) {
//                    int read = inputStream.read(bArr, 0, C2122b.f11939a);
//                    if (read == -1) {
//                        break;
//                    }
//                    fileOutputStream.write(bArr, 0, read);
//                }
//                if (fileOutputStream != null) {
//                    try {
//                        fileOutputStream.close();
//                    } catch (Exception e2) {
//                        e2.printStackTrace();
//                    }
//                }
//                return f3503k;
//            } catch (Exception e3) {
//                e = e3;
//            }
//        } catch (Exception e4) {
//            e = e4;
//            fileOutputStream = null;
//            try {
//                e.printStackTrace();
//                if (fileOutputStream == null) {
//                    return false;
//                }
//                try {
//                    fileOutputStream.close();
//                    return false;
//                } catch (Exception e5) {
//                    e5.printStackTrace();
//                    return false;
//                }
//            } catch (Throwable th2) {
//                th = th2;
//                if (fileOutputStream != null) {
//                    try {
//                        fileOutputStream.close();
//                    } catch (Exception e52) {
//                        e52.printStackTrace();
//                    }
//                }
//                throw th;
//            }
//        } catch (Throwable th3) {
//            th = th3;
//            fileOutputStream = null;
//            if (fileOutputStream != null) {
//                fileOutputStream.close();
//            }
//            throw th;
//        }
//    }

    public static boolean m8019a(Class<BluetoothDevice> cls, BluetoothDevice bluetoothDevice) {
        try {
            return ((Boolean) cls.getMethod("removeBond", new Class[0]).invoke(bluetoothDevice, new Object[0])).booleanValue();
        } catch (Exception e) {
            return false;
        }
    }

//    public static boolean m8020a(String str) {
//        if (TextUtils.isEmpty(str)) {
//            return false;
//        }
//        try {
//            return BraceletApp.m7879a().getPackageManager().getApplicationInfo(str, AsyncHttpClient.f15540e) != null ? f3503k : false;
//        } catch (NameNotFoundException e) {
//            return false;
//        }
//    }

//    public static boolean m8021a(String str, Bitmap bitmap) {
//        return m8022a(str, bitmap, 100);
//    }

//    public static boolean m8022a(String str, Bitmap bitmap, int i) {
//        Exception e;
//        Throwable th;
//        boolean z = false;
//        File file = new File(str);
//        if (file.exists()) {
//            file.delete();
//        }
//        FileOutputStream fileOutputStream;
//        try {
//            fileOutputStream = new FileOutputStream(file);
//            try {
//                z = bitmap.compress(Bitmap.CompressFormat.JPEG, i, fileOutputStream);
//                if (fileOutputStream != null) {
//                    try {
//                        fileOutputStream.close();
//                    } catch (IOException e2) {
//                    }
//                }
//            } catch (Exception e3) {
//                e = e3;
//                try {
//                    GuliLog.tracePrintError(f3504l, e.getMessage());
//                    if (fileOutputStream != null) {
//                        try {
//                            fileOutputStream.close();
//                        } catch (IOException e4) {
//                        }
//                    }
//                    return z;
//                } catch (Throwable th2) {
//                    th = th2;
//                    if (fileOutputStream != null) {
//                        try {
//                            fileOutputStream.close();
//                        } catch (IOException e5) {
//                        }
//                    }
//                    throw th;
//                }
//            }
//        } catch (Exception e6) {
//            e = e6;
//            fileOutputStream = null;
//            GuliLog.tracePrintError(f3504l, e.getMessage());
//            if (fileOutputStream != null) {
//                fileOutputStream.close();
//            }
//            return z;
//        } catch (Throwable th3) {
//            th = th3;
//            fileOutputStream = null;
//            if (fileOutputStream != null) {
//                fileOutputStream.close();
//            }
//            throw th;
//        }
//        return z;
//    }

    public static boolean m8023a(String str, String str2) {
        if (str.indexOf(58) <= 0 || str2.indexOf(58) <= 0) {
            return false;
        }
        try {
            try {
                return Integer.parseInt(str2.split(C4220a.ci)[0]) > Integer.parseInt(str.split(C4220a.ci)[0]) ? f3503k : false;
            } catch (Exception e) {
                return false;
            }
        } catch (Exception e2) {
            return false;
        }
    }

    public static boolean m8024a(Calendar calendar, Calendar calendar2) {
        if (calendar == null || calendar2 == null) {
            return f3503k;
        }
        int i = calendar.get(Calendar.YEAR);
        i = (i * 365) + calendar.get(Calendar.DAY_OF_YEAR);
        int i2 = (calendar2.get(Calendar.YEAR) * 365) + calendar2.get(Calendar.DAY_OF_YEAR);
        GuliLog.tracePrintInfo(f3504l, "totalA =" + i + ", totalB=" + i2);
        return i >= i2 ? false : f3503k;
    }

    public static String[] m8025a(int i, int i2, int i3) {
        String[][] a = BabyWeightUtil.m15905a().m15906a(i3, i2);
        return (i < 0 || i > 11) ? i <= 83 ? a[((i / 3) + 8) + 1] : new String[0] : a[i + 1];
    }

    public static float m8026b(float f, Context context) {
        return (((float) context.getResources().getDisplayMetrics().densityDpi) / 160.0f) * f;
    }

    public static int m8027b(long j) {
        Calendar instance = Calendar.getInstance();
        instance.setTimeInMillis(j);
        return instance.get(Calendar.MINUTE) + (instance.get(Calendar.DAY_OF_WEEK) * 60);
    }

    private static int m8028b(BitmapFactory.Options options, int i, int i2) {
        int i3 = options.outHeight;
        int i4 = options.outWidth;
        int i5 = 1;
        if (i3 > i2 || i4 > i) {
            i3 /= 2;
            i4 /= 2;
            while (i3 / i5 > i2 && i4 / i5 > i) {
                i5 *= 2;
            }
        }
        return i5;
    }

    public static int m8029b(DaySportData.Summary summary) {
        int b = m8027b(summary.getSleepStartTime());
        int b2 = m8027b(summary.getSleepRiseTime());
        return b2 >= b ? b2 - b : (1440 - b) + b2;
    }

    public static int m8030b(Calendar calendar) {
        return calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1;
    }

    public static long m8031b(Calendar calendar, Calendar calendar2) {
        Calendar instance = Calendar.getInstance();
        instance.clear();
        instance.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
        Calendar instance2 = Calendar.getInstance();
        instance2.clear();
        instance2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DATE));
        return (instance2.getTimeInMillis() - instance.getTimeInMillis()) / 86400000;
    }

    public static String m8032b(int i) {
        return new DecimalFormat("#.#").format((double) (((float) i) * 1.0E-4f));
    }

    public static String m8033b(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            String str = packageInfo.versionName;
            int i = packageInfo.versionCode;
            String str2 = packageInfo.packageName;
            return i + C4220a.ci + str;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String m8034b(Context context, String str) {
        try {
            String string = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128).metaData.getString(str);
            GuliLog.tracePrintInfo(f3504l, "hm_channel=" + string);
            return string;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return Constant.f3411f;
        }
    }

    public static String m8035b(byte[] bArr) {
        String str = C3657a.f18328f;
        if (bArr == null || bArr.length <= 0) {
            return str;
        }
        try {
            return new String(bArr);
        } catch (Exception e) {
            GuliLog.tracePrintInfo("chenee", "Utils.java getStringFromBytes error:" + e.getMessage());
            return str;
        }
    }

//    public static ArrayList<String> m8036b(SportDay sportDay) {
//        ArrayList<String> d = m8060d();
//        if (d == null) {
//            return null;
//        }
//        Iterator it = d.iterator();
//        while (it.hasNext()) {
//            String str = (String) it.next();
//            if (sportDay.toString().equals(str)) {
//                d.remove(str);
//            }
//        }
//        m8054c((ArrayList) d);
//        return d;
//    }

//    public static ArrayList<SportData> m8037b(ArrayList<SportData> arrayList) {
//        try {
//            OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//            new ObjectOutputStream(byteArrayOutputStream).writeObject(arrayList);
//            return (ArrayList) new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())).readObject();
//        } catch (Exception e) {
//            e.printStackTrace();
//            GuliLog.tracePrintInfo("WPJ", e.getMessage());
//            return new ArrayList();
//        }
//    }

    public static void m8038b(Activity activity) {
        DownloadManager downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
        DownloadManager.Query query = new DownloadManager.Query();
        long readDownloadApkId = Keeper.readDownloadApkId();
        query.setFilterById(new long[]{readDownloadApkId});
        Cursor query2 = downloadManager.query(query);
        if (query2.moveToFirst()) {
            switch (query2.getInt(query2.getColumnIndex("status"))) {
                case 1 /*1*/:
                    break;
                case C4220a.f20888k /*2*/:
                    break;
                case C4220a.aQ /*4*/:
                    GuliLog.m12370d(f3504l, "STATUS_PAUSED");
                    break;
                case C4220a.ba /*8*/:
                    GuliLog.m12370d(f3504l, "STATUS_SUCCESSFUL download_id=" + readDownloadApkId);
                    Uri uriForDownloadedFile = downloadManager.getUriForDownloadedFile(readDownloadApkId);
                    Intent intent = new Intent("android.intent.action.VIEW");
                    intent.setDataAndType(uriForDownloadedFile, "application/vnd.android.package-archive");
                    intent.setFlags(268435456);
                    activity.startActivity(intent);
                    C3247b.m22928a((Context) activity, (int) R.string.apk_download_ok, 1).show();
                    Keeper.keepDownloadApkId(-1);
                    return;
                case C4220a.bp /*16*/:
                    GuliLog.m12370d(f3504l, "STATUS_FAILED");
                    downloadManager.remove(new long[]{Keeper.readDownloadApkId()});
                    Keeper.keepDownloadApkId(-1);
                    C3247b.m22928a((Context) activity, (int) R.string.download_failed, 1).show();
                    return;
                default:
                    return;
            }
            GuliLog.m12370d(f3504l, "STATUS_PENDING");
            GuliLog.m12370d(f3504l, "STATUS_RUNNING");
        }
    }

    public static void m8039b(Activity activity, boolean z) {
        GuliLog.m12370d(f3504l, "checkXiaomiApkUpdate");
//        C4020d.m25868a(false);
//        C4020d.m25866a(new C0659U(activity, z));
//        C4020d.m25864a((Context) activity);
    }

    public static void m8040b(Context context, int i) {
//        SwitchOperator switchOperator = new SwitchOperator();
//        switchOperator.type = i;
//        switchOperator.enableClearData = f3503k;
//        switchOperator.enableSteps = f3503k;
//        switchOperator.lastUid = C0886a.m9071f(context).uid;
//        switchOperator.lastMacAddress = Keeper.readBraceletBtInfo().f19636b;
//        SportDay sportDay = new SportDay();
//        switchOperator.date = sportDay.getKey();
//        DaySportData.Summary c = DataManager.m12179a().m12215c(sportDay);
//        if (c != null) {
//            switchOperator.steps = c.getSteps();
//            GuliLog.m12370d(f3504l, "summary steps:" + switchOperator.steps);
//        } else {
//            GuliLog.m12370d(f3504l, "no summary steps!!!");
//        }
//        Keeper.keepSwitchOperator(switchOperator);
    }


    public static void m8041b(Context context, Bundle bundle, C0899d c0899d) {
        String string = bundle.getString("date");
        int i = bundle.getInt(ClientDataConstants.aw);
        int i2 = bundle.getInt(ClientDataConstants.ax);
//        WebAPI.m11595a(C0886a.m9071f(context), i, bundle.getInt("data_type"), i2, new C0655R(c0899d, string, i, i2, context));
    }

    @SuppressLint({"NewApi"})
    public static void m8042b(com.goodving.guli.bt.weight.UserInfo userInfo, ImageView imageView) {
        if (userInfo != null) {
            if (userInfo.uid == -1) {
                Bitmap bitmap;
                PersonInfo readPersonInfoForScale = Keeper.readPersonInfoForScale();
                GuliLog.tracePrintInfo(f3504l, "read the person info avatarPath is " + readPersonInfoForScale.avatarPath);
                if (readPersonInfoForScale.avatarPath == null || readPersonInfoForScale.avatarPath.isEmpty()) {
                    bitmap = null;
                } else {
                    bitmap = C1226h.m11372a().m11375a(Uri.fromFile(new File(readPersonInfoForScale.avatarPath)).toString());
                }
                if (bitmap != null) {
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    try {
                        bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                        userInfo.avatarSource = byteArrayOutputStream.toByteArray();
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e) {
                            }
                        }
                    } catch (Exception e2) {
                        GuliLog.tracePrintError(f3504l, e2.getMessage());
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e3) {
                            }
                        }
                    } catch (Throwable th) {
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e4) {
                            }
                        }
                    }
                    bitmap.recycle();
                }
            }
            if (null == null && userInfo.avatarSource != null && userInfo.avatarSource.length > 0) {
                byte[] bArr = userInfo.avatarSource;
                Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length);
                GuliLog.tracePrintInfo(f3504l, "path=" + userInfo.avatarUrl);
                if (decodeByteArray != null) {
                    imageView.setBackground(new BitmapDrawable(C1894O.m15165a(decodeByteArray)));
                    GuliLog.tracePrintInfo(f3504l, "set background from avatarSource");
                    decodeByteArray.recycle();
                    return;
                }
                imageView.setBackgroundResource(R.drawable.person_avatar_default_blue);
                return;
            } else if (!(userInfo.avatarUrl == null || userInfo.avatarUrl.equals(C3657a.f18328f))) {
                imageView.setBackgroundResource(R.drawable.person_avatar_default_blue);
                GuliLog.tracePrintInfo(f3504l, "avatar Url =" + userInfo.avatarUrl);
                C1226h.m11372a().m11383b(userInfo.avatarUrl, imageView);
                return;
            }
        }
        imageView.setBackgroundResource(R.drawable.person_avatar_default_blue);
    }
//
//    private static void m8043b(C4018b c4018b, Activity activity) {
//        if (activity == null || c4018b == null) {
//            GuliLog.m12370d(f3504l, "showUpdateDlg return with NULL pointer!");
//            return;
//        }
//        String str = C3657a.f18328f;
//        if (!TextUtils.isEmpty(c4018b.f20144a)) {
//            GuliLog.m12370d(f3504l, "mi shop updateLog=" + c4018b.f20144a);
//            str = c4018b.f20144a;
//        }
//        Bundle bundle = new Bundle();
//        bundle.putString(f3500h, c4018b.f20145b);
//        bundle.putString(f3499g, str);
//        bundle.putString(f3501i, c4018b.f20147d);
//        DimPanelFragment.showPanel(activity, C1839j.class, bundle);
//    }
//
//    public static final boolean m8044b() {
//        GuliLog.tracePrintInfo(f3504l, "Sdk : " + VERSION.SDK_INT + " model:" + Build.MODEL);
//        return VERSION.SDK_INT >= 18 ? f3503k : false;
//    }

    public static boolean m8045b(String str) {
        return (str != null && str.length() >= 1 && str.length() <= 20) ? f3503k : false;
    }

//    public static boolean m8046b(String str, Bitmap bitmap) {
//        Exception e;
//        Throwable th;
//        boolean z = false;
//        File file = new File(str);
//        if (file.exists()) {
//            file.delete();
//        }
//        FileOutputStream fileOutputStream;
//        try {
//            fileOutputStream = new FileOutputStream(file);
//            try {
//                z = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
//                if (fileOutputStream != null) {
//                    try {
//                        fileOutputStream.close();
//                    } catch (IOException e2) {
//                    }
//                }
//            } catch (Exception e3) {
//                e = e3;
//                try {
//                    GuliLog.tracePrintError(f3504l, e.getMessage());
//                    if (fileOutputStream != null) {
//                        try {
//                            fileOutputStream.close();
//                        } catch (IOException e4) {
//                        }
//                    }
//                    return z;
//                } catch (Throwable th2) {
//                    th = th2;
//                    if (fileOutputStream != null) {
//                        try {
//                            fileOutputStream.close();
//                        } catch (IOException e5) {
//                        }
//                    }
//                    throw th;
//                }
//            }
//        } catch (Exception e6) {
//            e = e6;
//            fileOutputStream = null;
//            GuliLog.tracePrintError(f3504l, e.getMessage());
//            if (fileOutputStream != null) {
//                fileOutputStream.close();
//            }
//            return z;
//        } catch (Throwable th3) {
//            th = th3;
//            fileOutputStream = null;
//            if (fileOutputStream != null) {
//                fileOutputStream.close();
//            }
//            throw th;
//        }
//        return z;
//    }

    public static float m8047c(float f, Context context) {
        return f / (((float) context.getResources().getDisplayMetrics().densityDpi) / 160.0f);
    }

    public static int m8048c(int i) {
        return f3510r[(i + 1) % 6];
    }

    public static Gson m8049c() { // C2576k is Gson
        if (mGson == null) {
            synchronized (Utils.class) {
                if (mGson == null) {
                    mGson = new GsonBuilder().create(); // C2584r
                }
            }
        }
        return mGson;
    }

    public static String m8050c(SportDay sportDay) {
        Date date = new Date();
        date.setYear(sportDay.year - 1900);
        date.setMonth(sportDay.mon);
        date.setDate(sportDay.day);
        return new SimpleDateFormat(C1481u.getContext().getString(R.string.date_year_month_day)).format(date);
    }

    public static String m8051c(String str) {
        return (str == null || str.equals("null")) ? C3657a.f18328f : str;
    }

//    public static void m8052c(Context context) {
//        WebAPI.m11627c(context, new C0662W(context));
//    }

    public static void m8053c(Context context, int i) {
        m8040b(context, i);
        XMBLEManager.m25155b();
        Intent intent = new Intent();
        intent.setAction(Constant.aX);
        context.sendBroadcast(intent);
    }

//    private static void m8054c(ArrayList<String> arrayList) {
//        JSONException e;
//        if (arrayList != null) {
//            JSONObject jSONObject;
//            try {
//                jSONObject = new JSONObject(Keeper.readLazyDays());
//                try {
//                    jSONObject.put(C4220a.cl, m8049c().toJson((Object) arrayList));
//                } catch (JSONException e2) {
//                    e = e2;
//                    e.printStackTrace();
//                    if (jSONObject != null) {
//                        Keeper.keepLazyDays(jSONObject.toString());
//                    }
//                    GuliLog.tracePrintInfo(f3504l, "after cope with lazy days: " + jSONObject);
//                }
//            } catch (JSONException e3) {
//                e = e3;
//                jSONObject = null;
//                e.printStackTrace();
//                if (jSONObject != null) {
//                    Keeper.keepLazyDays(jSONObject.toString());
//                }
//                GuliLog.tracePrintInfo(f3504l, "after cope with lazy days: " + jSONObject);
//            }
//            if (jSONObject != null) {
//                Keeper.keepLazyDays(jSONObject.toString());
//            }
//            GuliLog.tracePrintInfo(f3504l, "after cope with lazy days: " + jSONObject);
//        }
//    }

    public static boolean m8055c(Activity activity) {
        List runningTasks = ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1);
        if (!(runningTasks == null || runningTasks.isEmpty())) {
            ComponentName componentName = ((ActivityManager.RunningTaskInfo) runningTasks.get(0)).topActivity;
            if (componentName.getPackageName().equals(activity.getPackageName()) && componentName.getClassName().equals(activity.getComponentName().getClassName())) {
                return f3503k;
            }
        }
        return false;
    }

    public static String m8056d(Context context) {
        return m7982a(context, "ro.build.date.utc");
    }

    public static String m8057d(Context context, int i) {
        int i2 = i / 12;
        int i3 = i - ((i / 12) * 12);
        if (i2 != 0 && i3 != 0) {
            return context.getString(R.string.baby_weight_report_monthyear_templates0, new Object[]{i2 + C3657a.f18328f, i3 + C3657a.f18328f});
        } else if (i2 != 0) {
            return i2 + context.getString(R.string.year);
        } else {
            if (i3 != 0) {
                return context.getString(R.string.baby_weight_report_monthyear_templates1, new Object[]{i3 + C3657a.f18328f});
            }
            return context.getString(R.string.baby_weight_report_monthyear_templates1, new Object[]{f3498f});
        }
    }

    public static String m8058d(SportDay sportDay) {
        Date date = new Date();
        date.setYear(sportDay.year - 1900);
        date.setMonth(sportDay.mon);
        date.setDate(sportDay.day);
        return new SimpleDateFormat(C1481u.getContext().getString(R.string.date_month_day)).format(date);
    }

    public static String m8059d(String str) {
        String replace = str.replace("+", C3657a.f18328f);
        if (replace.startsWith("86")) {
            replace = replace.substring(2, replace.length());
        }
        String str2 = C3657a.f18328f;
        int i = 0;
        while (i < replace.length()) {
            try {
                int random = (int) (Math.random() * 3.0d);
                str2 = str2 + f3507o[Integer.valueOf(replace.charAt(i) + C3657a.f18328f).intValue()].charAt(random);
                i++;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return str2;
    }

    static final class C0661V extends TypeToken<ArrayList<String>> {
        C0661V() {
        }
    }

    public static ArrayList<String> m8060d() {
        String optString;
        try {
            optString = new JSONObject(URLDecoder.decode(Keeper.readLazyDays())).optString(C4220a.cl);
        } catch (JSONException e) {
            e.printStackTrace();
            optString = null;
        }
        if (optString == null) {
            return null;
        }
        ArrayList<String> arrayList;
        try {
            arrayList = (ArrayList) m8049c().fromJson(optString, new C0661V().getType()); // m19543a
        } catch (Exception e2) {
            e2.printStackTrace();
            arrayList = null;
        }
        return arrayList;
    }

    public static String m8061e(Context context) {
        return m7982a(context, "ro.build.version.incremental");
    }

    private static String m8062e(Context context, int i) {
        DecimalFormat decimalFormat = new DecimalFormat("#.#");
        String str = C3657a.f18328f;
        str = f3498f;
        float f = ((float) i) / C4220a.bQ;
        float round = (float) Math.round(f);
        if (round > f) {
            round -= 0.5f;
        }
        String format;
        if (((float) i) > C4220a.bQ) {
            format = decimalFormat.format((double) round);
            if (((double) Math.abs(round - f)) < 0.1d) {
                str = context.getString(R.string.marathon_format_0, new Object[]{format});
            } else {
                str = context.getString(R.string.marathon_format_1, new Object[]{format});
            }
        } else if (Math.abs(i - 21000) < C4220a.aB) {
            str = context.getString(R.string.half_marathon_format_0, new Object[]{Constants.VIA_TO_TYPE_QQ_GROUP});
        } else if (i > 21000) {
            str = context.getString(R.string.half_marathon_format_1);
        } else {
            f = ((float) i) / C4220a.bP;
            round = (float) Math.round(f);
            if (round > f) {
                round -= 0.5f;
            }
            format = decimalFormat.format((double) round);
            if (round == 0.0f) {
                str = C3657a.f18328f;
            } else {
                str = context.getString(R.string.share_play_ground_format, new Object[]{format});
            }
        }
        GuliLog.tracePrintInfo(f3504l, "maraton:" + i + ", str=" + str);
        return str;
    }

    public static String m8063e(SportDay sportDay) {
        return (sportDay.mon + 1) + "/" + sportDay.day;
    }

    public static String m8064e(String str) {
        GuliLog.tracePrintInfo(f3504l, "\n====>         before purge json :" + str);
        String replace = str.replace("\"[", "[").replace("]\"", "]").replace("}\"", "}").replace("\"{", "{").replace("\\\"", "\"").replace("\\/", "/");
        GuliLog.tracePrintInfo(f3504l, "\n====>         after purge json([], {},\\\", \\/) :" + replace);
        return replace;
    }

    public static boolean m8065e() {
        return DeviceSource.hasBindBracelet();
    }

    private static long m8066f(SportDay sportDay) {
        return sportDay.calendar.getTimeInMillis() / 1000;
    }

    public static String m8067f(Context context) {
        return m7982a(context, "ro.miui.ui.version.code");
    }

    public static String m8068f(String str) {
        try {
            str = URLDecoder.decode(str, C4220a.bO);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }

    public static boolean m8069f() {
        return Keeper.readPersonInfoBaseConfig().isInComingCallEnabled();
    }

    public static String m8070g(Context context) {
        return m7982a(context, "ro.miui.ui.version.name");
    }

    public static boolean m8071g() {
        BraceletBtInfo readBraceletBtInfo = Keeper.readBraceletBtInfo();
        return (readBraceletBtInfo == null || TextUtils.isEmpty(readBraceletBtInfo.f19636b)) ? false : f3503k;
    }

    public static boolean m8072g(String str) {
        return (!(((str.contains("'") | str.contains("\"")) | str.contains("\\")) | str.contains("/")))? f3503k : false;
    }

    public static String m8073h(Context context) {
        String line1Number = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
        GuliLog.tracePrintInfo(f3504l, "get tel =" + line1Number);
        return line1Number == null ? C3657a.f18328f : line1Number;
    }

    public static String m8074h(String str) {
        if (str.length() > 10) {
            str = str.substring(0, 10) + "...";
        }
        GuliLog.tracePrintInfo(f3504l, str);
        return str;
    }

    public static boolean m8075h() {
        return Build.DEVICE.equalsIgnoreCase("virgo");
    }

    public static void handleUUID(Context context) {
        String readUUID = Keeper.readUUID();
        if (readUUID == null || readUUID.length() < 1) {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String str = " " + telephonyManager.getDeviceId();
            readUUID = " " + telephonyManager.getSimSerialNumber();
            String str2 = " " + Settings.Secure.getString(context.getContentResolver(), "android_id");
            String str3 = " " + BluetoothAdapter.getDefaultAdapter().getAddress();
            UUID uuid = new UUID((long) (str3.hashCode() | str2.hashCode()), (long) (str.hashCode() | readUUID.hashCode()));
            GuliLog.m12360b(f3504l, "\ndeviceId:" + str + "\nserialNum:" + readUUID + "\nandroidId:" + str2 + "\nmacAddress:" + str3 + "\nuuid:" + uuid.toString());
            Keeper.keepUUID(uuid.toString());
        }
    }

    public static String m8076i(Context context) {
        LoginData f = C0886a.m9071f(context);
        String str = C3657a.f18328f;
        if (f == null) {
            return str;
        }
        HashMap hashMap = new HashMap();
        hashMap.put(SyncServerData.f8320f, C3657a.f18328f + f.uid);
        hashMap.put(C4220a.f20892o, f.security);
        hashMap.put(Friend.f7787c, Keeper.readUserName());
        return ClientConstant.m11562a(hashMap);
    }

    public static String m8077i(String str) {
        float f = -1.0f;
        try {
            f = Float.parseFloat(str);
        } catch (Exception e) {
        }
        return f < 0.0f ? C3657a.f18328f : f + C3657a.f18328f;
    }

    public static boolean m8078i() {
        return Build.DEVICE.equalsIgnoreCase("leo");
    }

    public static String m8079j(Context context) {
        String externalStorageState = Environment.getExternalStorageState();
        GuliLog.tracePrintInfo(f3504l, "ext state =" + externalStorageState);
        File externalFilesDir = "mounted".equals(externalStorageState) ? context.getExternalFilesDir(f3508p) : context.getFilesDir();
        if (externalFilesDir == null) {
            externalFilesDir = context.getFilesDir();
        }
        if (externalFilesDir == null) {
            return Environment.getExternalStorageDirectory().getPath() + "/" + f3508p;
        }
        externalStorageState = externalFilesDir.getPath();
        GuliLog.tracePrintInfo(f3504l, "getStoragePath:" + externalStorageState);
        return externalStorageState;
    }

//    public static boolean m8081j() {
//        int daySportGoalSteps = Keeper.readPersonInfo().getDaySportGoalSteps();
//        DaySportData g = DataManager.m12179a().m9052g(DataManager.m12179a().m9056m());
//        return (g == null || g.getStepsInfo() == null || g.getStepsInfo().getStepsCount() < daySportGoalSteps) ? false : f3503k;
//    }

    private static List<WeightGoal> m8082k(String str) {
        List<WeightGoal> arrayList = new ArrayList();
        try {
            JSONArray jSONArray = new JSONObject(str).getJSONObject("data").getJSONArray("list");
            for (int i = 0; i < jSONArray.length(); i++) {
                arrayList.add(new WeightGoal(jSONArray.getJSONObject(i)));
            }
        } catch (Exception e) {
            GuliLog.tracePrintInfo(f3504l, "parse error");
        }
        return arrayList;
    }

    public static boolean m8083k() {
        return Config.m8876h().f4213w.booleanValue();
    }

    public static boolean m8084k(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        return connectivityManager.getActiveNetworkInfo() != null ? connectivityManager.getActiveNetworkInfo().isConnected() : false;
    }

    public static float m8085l() {
        WeightInfoManager a = WeightInfoManager.getInstance();
        Calendar instance = Calendar.getInstance();
        instance.set(Calendar.HOUR_OF_DAY, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        GuliLog.tracePrintInfo(f3504l, "today before:" + new SimpleDateFormat("dd HH:mm:ss").format(Long.valueOf(instance.getTimeInMillis())));
        WeightInfo a2 = a.m15744a(-1, instance.getTimeInMillis());
        float weight = a2 != null ? a2.weight : Keeper.readPersonInfo().getWeight();
        GuliLog.tracePrintInfo(f3504l, " calorie weight :" + weight);
        return weight;
    }

    public static boolean m8086l(Context context) {
        String a = m7982a(context, "sys.keyguard.bleunlock");
        GuliLog.tracePrintInfo(f3504l, "unlock:" + a);
        return (a == null || !a.equals("true")) ? false : f3503k;
    }

    public static boolean m8087m() {
        Locale locale = Locale.getDefault();
        return (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) ? false : f3503k;
    }

    public static boolean m8088m(Context context) {
//        if (C0634B.m7842a(context, C0634B.f3357d)) {
//            return ((SensorManager) context.getSystemService("sensor")).getDefaultSensor(18) == null ? false : !C0894g.m9096a(context, C1225h.f6465i) ? false : !C1223f.m11356a(context.getContentResolver()) ? false : f3503k;
//        } else {
//            GuliLog.m12370d(f3504l, "not support miui sensorhub!!!");
//            return false;
//        }
        return false;
    }

//    public static String m8089n() {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BraceletApp.m7879a().getString(R.string.date_month_day));
//        Calendar instance = Calendar.getInstance();
//        instance.add(2, -1);
//        instance.set(5, 1);
//        String format = simpleDateFormat.format(instance.getTime());
//        instance.set(5, 1);
//        instance.add(2, 1);
//        instance.add(5, -1);
//        return format + " - " + simpleDateFormat.format(instance.getTime());
//    }

    public static boolean m8090n(Context context) {
        boolean z = f3503k;
        try {
            int i = Settings.Secure.getInt(context.getContentResolver(), "bluetooth_unlock_status");
            String string = Settings.Secure.getString(context.getContentResolver(), "bluetooth_address_to_unlock");
            String str = Keeper.readBraceletBtInfo().f19636b;
            GuliLog.m12370d(f3504l, "isUseUnlock:" + i + ",unlockAddress:" + string + " , mDeviceAddress = " + str);
            if (string == null || C3657a.f18328f.equals(string) || !string.equals(str)) {
                return false;
            }
            if (i != 1) {
                z = false;
            }
            return z;
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

//    public static String m8091o() {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BraceletApp.m7879a().getString(R.string.date_month_day));
//        Calendar instance = Calendar.getInstance();
//        int i = instance.get(7);
//        instance.add(5, (i == 1 ? -6 : 2 - i) - 7);
//        String format = simpleDateFormat.format(instance.getTime());
//        instance.add(5, 6);
//        return format + " - " + simpleDateFormat.format(instance.getTime());
//    }

//    public static boolean m8092o(Context context) {
//        if (!WXAPIFactory.createWXAPI(context, C3269m.f16875j).isWXAppInstalled()) {
//            return false;
//        }
//        try {
//            return context.getPackageManager().getPackageInfo(WXApp.WXAPP_PACKAGE_NAME, 0).versionCode >= C4220a.ax ? f3503k : false;
//        } catch (PackageManager.NameNotFoundException e) {
//            return false;
//        }
//    }

    public static UserInfo m8093p() {
        PersonInfo readPersonInfo = Keeper.readPersonInfo();
        return readPersonInfo.isValid() ? m7973a(readPersonInfo) : null;
    }

    public static void m8094p(Context context) {
        String b = m8033b(context);
        if (!TextUtils.isEmpty(b) && !b.equals(Keeper.readApkVersion())) {
            Keeper.keepApkVersion(b);
        }
    }

//    public static C3941i m8095q() {
//        PersonInfo readPersonInfo = Keeper.readPersonInfo();
//        return readPersonInfo.isValid() ? readPersonInfo.getMiLiHwConfig() : null;
//    }

//    public static void m8096q(Context context) {
//        if (m8084k(context)) {
//            Config h = Config.m8876h();
//            if (h.f4213w.booleanValue()) {
//                h.getClass();
//                m8011a("https://hm.mi-ae.com/huami.health.agreement.do", (int) R.string.user_agreement, context, 3);
//                return;
//            }
//            h.getClass();
//            m8011a("https://hm.goodving.com/huami.health.agreement.do", (int) R.string.user_agreement, context, 3);
//            return;
//        }
//        C3247b.m22928a(context, (int) R.string.network_error, 1).show();
//    }

//    public static boolean m8097r(Context context) {
//        return m8034b(context, Constant.f3409d).equals(Constant.f3411f);
//    }
//
    public static void m8098s(Context context) {
//        WebAPI.m11589a(context, new C0663X(), URLEncoder.encode(Keeper.readLazyDays()));
    }

    public static void m8099t(Context context) {
        DataManager a = DataManager.m12179a();
        SportDay m = DataManager.m12179a().m9056m();
        DaySportData g = a.m9052g(m);
        if (g != null) {
            StepsInfo stepsInfo = g.getStepsInfo();
            if (stepsInfo != null && stepsInfo.getStepsCount() >= Keeper.readPersonInfo().getDaySportGoalSteps()) {
//                m8036b(m);
//                m8098s(context);
            }
        }
    }

    public static boolean m8100u(Context context) {
        return (!m7958A(context) || m7959B(context)) ? false : f3503k;
    }
//
//    public static boolean m8101v(Context context) {
//        Partner a = C0855b.m8954a(context).m8957a("2833961550");
//        GuliLog.tracePrintInfo(f3504l, "bohee partner info : " + a.title + " " + a.authorizeStatus);
//        return 1 == a.authorizeStatus ? f3503k : false;
//    }
//
    public static boolean m8102w(Context context) {
        return LuaUtil.getInstance(context).m15964a("2833961550");
    }

    public static boolean m8103x(Context context) {
        return DateFormat.is24HourFormat(context);
    }

    static final class C0656S extends AsyncHttpResponseHandler {
        C0656S() {
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.m12370d("Utils", "uploadIMEI fail");
            Keeper.setUploadImeiStatus(0);
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            if (bArr != null) {
                String str = new String(bArr);
                GuliLog.m12370d("Utils", "Response uploadIMEI: " + str);
                try {
                    if (((Integer) new JSONObject(str).get("code")).intValue() == 1) {
                        Keeper.setUploadImeiStatus(1);
                        return;
                    } else {
                        Keeper.setUploadImeiStatus(0);
                        return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    Keeper.setUploadImeiStatus(0);
                    return;
                }
            }
            GuliLog.m12370d("Utils", "Response uploadIMEI return null");
            Keeper.setUploadImeiStatus(0);
        }
    }

    public static void m8104y(Context context) {
        LoginData f = C0886a.m9071f(context);
        if (f.isValid()) {
            Keeper.setUploadImeiStatus(-1);
            WebAPI.m11585a(context, f, new C0656S());
            return;
        }
        GuliLog.m12370d(f3504l, "uploadIMEI loginData not valid.");
    }

    public static String m8105z(Context context) {
        Display defaultDisplay = ((Activity) context).getWindowManager().getDefaultDisplay();
        int width = defaultDisplay.getWidth();
        int height = defaultDisplay.getHeight();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(height).append("x").append(width);
        return stringBuffer.toString();
    }
}
